import 'package:flutter/material.dart';

import '../common/app_color.dart';
import 'dialog_container.dart';

class AppDialog extends StatelessWidget {
  final String content;
  final String? cancelText;
  final VoidCallback? onConfirm;
  final VoidCallback? onCancel;
  String? title;

  AppDialog({Key? key, this.title, required this.content, this.cancelText, this.onConfirm, this.onCancel})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return DialogContainer(
      backgroundColor: AppColors.white,
      child: Container(
        width: 280,
        decoration: BoxDecoration(color: AppColors.white, borderRadius: BorderRadius.circular(6)),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              padding: const EdgeInsets.only(top: 12),
              child: Text(
                title ?? "提示",
                style: const TextStyle(color: AppColors.black, fontSize: 18, fontWeight: FontWeight.bold),
              ),
            ),
            Container(
              margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
              child: SelectableText (
                content,
                style: const TextStyle(fontSize: 16, color: AppColors.c33, fontWeight: FontWeight.w400),
              ),
            ),
            const Divider(
              height: 1,
              color: AppColors.c5,
            ),
            SizedBox(
              height: 64,
              child: Row(
                children: [
                  cancelText == null
                      ? const SizedBox()
                      : Flexible(
                          child: InkWell(
                          splashColor: Colors.transparent,
                          highlightColor: Colors.transparent,
                          child: Container(
                            alignment: Alignment.center,
                            child:  Text(
                              cancelText??"取消",
                              style: const TextStyle(color: AppColors.c99, fontSize: 16),
                            ),
                          ),
                          onTap: () {
                            Navigator.of(context).pop();
                            if (onCancel != null) {
                              onCancel!();
                            }
                            // exit(0);
                          },
                        )),
                  cancelText == null
                      ? const SizedBox()
                      : Container(
                          color: AppColors.c5,
                          height: 64,
                          width: 1,
                        ),
                  // VerticalDivider(
                  //           color: AppColors.gray_99,
                  //         ),

                  Flexible(
                      child: InkWell(
                    splashColor: Colors.transparent,
                    highlightColor: Colors.transparent,
                    child: Container(
                      alignment: Alignment.center,
                      child: const Text(
                        "确定",
                        style: TextStyle(color: AppColors.primary, fontSize: 16, fontWeight: FontWeight.w600),
                      ),
                    ),
                    onTap: () {
                      Navigator.of(context).pop();
                      if (onConfirm != null) {
                        onConfirm!();
                      }
                    },
                  ))
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
